<?php
function security_on($str){
  return mysql_escape_string(htmlspecialchars($str));
}

function safe_request_null($name){
    if(isset($_REQUEST[$name])){
    return security_on($_REQUEST[$name]);
  }else{
    return "";
  }
}

function curlUsingGetWithData($url, $data)
{
    if(empty($url))
    {
        return 'Error: invalid Url or Data';
    }
	$fields_string = '';
	foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
	$fields_string = rtrim($fields_string,'&');
	$ch = curl_init();
	$url = $url."?".$fields_string;
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); # timeout after 10 seconds, you can increase it
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  # Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); # Some server may refuse your request if you dont pass user agent
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	$result = curl_exec($ch);
	curl_close($ch);
	return $result;
}


function curlUsingGet($url)
{
    if(empty($url))
    {
        return 'Error: invalid Url or Data';
    }
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); # timeout after 10 seconds, you can increase it
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  # Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); # Some server may refuse your request if you dont pass user agent
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	$result = curl_exec($ch);
	curl_close($ch);
	return $result;
}

function duration($start_time,$end_time){
$diff = $end_time - $start_time;
if($diff > 86400)
	return round(($diff/86400))." Days";
if($diff > 3600)
	return round(($diff/3600))." Hours";
if($diff > 60)
	return round(($diff/60))." Minutes";	
}

function shorten($str,$number){
	$retstr = substr($str, 0, $number);
	if(strlen($retstr) < strlen($str))
		return $retstr."...";
	else
		return $retstr;
}

?>